package com.ctgu.frequence.step2;

import com.ctgu.frequence.Utils.GetString;
import com.ctgu.frequence.Utils.ValueComparator;
import com.ctgu.frequence.step1.CountWord;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class IgnoreStopWords {
    public static void ignoreStopWords(String str) throws IOException {
        Map<String, Integer> map = CountWord.getWordMap(str);
        String stopWordPath = "E:\\学期学习\\大三上\\软件工程\\Gitcode\\se_test\\stopwords_en.txt";
        //统计停词表中的单词
        String stopWordStr = GetString.getString(new File(stopWordPath));
        String[] stopWords = stopWordStr.split("\\W+");
        //移除map中停词表的单词
        for (String s : stopWords){
            map.remove(s);
        }
        //对map进行排序
        List<Map.Entry<String,Integer>> ls=new ArrayList<>();
        ls.addAll(map.entrySet());
        ValueComparator vc=new ValueComparator();
        Collections.sort(ls,vc);
        for(Map.Entry<String, Integer> item:ls){
            System.out.println(item.getKey()+"出现的次数为："+item.getValue());
        }
    }
}
